package pl.edu.amu.wmi.kino.visualjavafx.model.animation.transformations;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import pl.edu.amu.wmi.kino.visualjavafx.model.animation.interpolators.Interpolation;
import pl.edu.amu.wmi.kino.visualjavafx.model.objects.VisualObject;

// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.65F8DF41-E7F5-FEBA-6CFE-42334537AB28]
// </editor-fold>
/**
 * Default values for all paramters are Double.NaN, set only those you really wish to change,
 * all unchanged parameters will NOT be generated in javafx code and it will work just fine
 * @author Admin
 */
public class Rotation implements Transformation ,java.io.Serializable{

    // Code block for changeListeners support start
    protected PropertyChangeSupport propertySupport= new PropertyChangeSupport(this);
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.addPropertyChangeListener(listener);
    }
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.removePropertyChangeListener(listener);
    }
    // Code block for changeListeners support end

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.3D1C9F2A-09EC-B42F-D28F-DF8ECFBFDDB4]
    // </editor-fold> 
    public Rotation () {
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.1FDD53F5-145A-C12C-4478-D92698F63871]
    // </editor-fold> 
    @Override
    public Interpolation getInterpolation () {
        return this.myInterpolations[0];
    }

    @Override
    public Interpolation[] getInterpolations() {
        return this.myInterpolations;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.5F370D86-784C-2954-504A-74D7C8CB34D0]
    // </editor-fold> 
    @Override
    public void setInterpolation (Interpolation i) {
        Interpolation oldVal = this.myInterpolations[0];
        this.myInterpolations[0]=i;
        this.myInterpolations[1]=i;
        this.myInterpolations[2]=i;
        propertySupport.firePropertyChange( "Inerpolation" , oldVal, i);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.FD223C6D-E646-F867-9771-D6D6D412F606]
    // </editor-fold> 
    @Override
    public VisualObject transform (double howMuch, VisualObject transformable,VisualObject orginalTransformedObject) {
        
        double rotation = this.getInterpolations()[0].getValue(howMuch,
                transformable.getRotation(), this.destinedRotationAngle);
        double anchorX = this.getInterpolations()[1].getValue(howMuch,
                transformable.getHCenterDelta(), this.destinedHCenter);
        double anchorY = this.getInterpolations()[2].getValue(howMuch,
                transformable.getVCenterDelta(), this.destinedVCenter);

        transformable.setRotation(rotation);
        transformable.setHCenterDelta(anchorX);
        transformable.setVCenterDelta(anchorY);
        return transformable;

    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.630BC6DB-97DF-F3AF-DBF4-C0B40CC8018B]
    // </editor-fold> 
    public double getDestinedRotationAngle () {
        return this.destinedRotationAngle;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.86ED4745-F307-66B2-98B8-077B175BA450]
    // </editor-fold> 
    public double getDestinedVCenter () {
        return this.destinedVCenter;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.FF2B426C-FC2D-453C-7C5D-4FB3CE4323B9]
    // </editor-fold> 
    public double getDestinedHcenter () {
        return this.destinedHCenter;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.DE474F63-11E6-D165-FC26-C2A455BE2705]
    // </editor-fold> 
    public void setDestinedRotationAngle (double val) {
        double oldVal = this.destinedRotationAngle;
        this.destinedRotationAngle=val;
        propertySupport.firePropertyChange( "destinedRotationAngle" , oldVal, val);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.D9743017-82C2-D4CB-7922-6E6B6E479B9E]
    // </editor-fold> 
    public void setDestinedVCenter (double val) {
        double oldVal = this.destinedVCenter;
        this.destinedVCenter=val;
        propertySupport.firePropertyChange( "destinedVCenter" , oldVal, val);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.DB7063F9-86A9-A688-2F97-1DC256C5F5BB]
    // </editor-fold> 
    public void setDestinedHCenter (double val) {
        double oldVal = this.destinedHCenter;
        this.destinedHCenter=val;
        propertySupport.firePropertyChange( "destinedHCenter" , oldVal, val);
    }

    private Interpolation[] myInterpolations=new Interpolation[3];
    private double destinedRotationAngle=Double.NaN;
    private double destinedHCenter=Double.NaN;
    private double destinedVCenter=Double.NaN;


    
    

}

